package com.rock.platform.interceptor;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.rock.platform.action.BaseAction;
import com.rock.platform.util.SessionUtils;

public class ActionSessionInterceptor extends AbstractInterceptor {
	private static final long serialVersionUID = -969877580458117679L;

	public String intercept(ActionInvocation invocation) throws Exception {
		Object userId = SessionUtils.getAttribute(SessionUtils.SKEY_USERID);
		if ((userId == null) || ("".equals(userId.toString()))) {
			return "login";
			//throw new BaseException("Invalid User,Please Sign in!");
		}

		Object action = invocation.getAction();
		if (action instanceof BaseAction) {
			((BaseAction) action).setLoginBean(SessionUtils.getLoginBean());
		}

		return invocation.invoke();
	}
}
